package com.oracle.lingshangejia.adapter;

import android.content.Context;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.activity.CheckupHealthActivity;
import com.oracle.lingshangejia.bean.CheckupHealthBean;

import java.util.List;

public class CheckupHealthAdapter extends RecyclerView.Adapter<CheckupHealthAdapter.ViewHolder> {

    private Context context;
    private List<CheckupHealthBean.DataBean> data;
    private OnItemClickListener onItemClickListener;

    public CheckupHealthAdapter(CheckupHealthActivity context, List<CheckupHealthBean.DataBean> data) {
        this.context=context;
        this.data=data;
    }

    public interface  OnItemClickListener{
        void onItemClick(View view, int postion);
    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public CheckupHealthAdapter(Context context){

        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_checkuphealth,null);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        viewHolder.tv_datahealth.setText(data.get(i).getTjrq());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener!=null) {
                    onItemClickListener.onItemClick(viewHolder.itemView,i);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return data!=null?data.size():0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_datahealth;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_datahealth=itemView.findViewById(R.id.tv_datahealth);
        }
    }
}
